<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="util" uri="functions"%>

<!DOCTYPE html>
<html lang="en">
<head>
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
<link type="text/css" rel="stylesheet" href="/plugins/zTree/2.6/zTreeStyle.css" />

<style type="text/css">
footer {
	height: 50px;
	position: fixed;
	bottom: 0px;
	left: 0px;
	width: 100%;
	text-align: center;
}
</style>

</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
							<div id="zhongxin">
								<div style="overflow: scroll; scrolling: yes; height: 415px; width: 319px;">
									<ul id="tree" class="tree" style="overflow: auto;"></ul>
								</div>
							</div>
							<div id="zhongxin2" class="center" style="display: none">
								<br />
								<br />
								<br />
								<br />
								<img src="/static/images/jiazai.gif" />
								<br />
								<h4 class="lighter block green">正在保存...</h4>
							</div>
						</div>
						<!-- /.col -->
					</div>
				</div>
				<!-- /.row -->
			</div>
			<!-- /.page-content -->
		</div>
	</div>
	<!-- /.main-content -->

	<div id="div_buttons" style="width: 100%; padding-top: 5px;" class="center">
		<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
		<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
	</div>
	<%@ include file="../../system/index/foot.jsp"%>
	<script type="text/javascript" src="/plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
	<script src="/static/ace/js/bootbox.js"></script>
	<script type="text/javascript">
		$(top.hangge());
		var zTree;
		$(document).ready(function() {

			var setting = {
				showLine : true,
				checkable : true
			};
			var zn = '${zTreeNodes}';
			var zTreeNodes = eval(zn);
			zTree = $("#tree").zTree(setting, zTreeNodes);
		});

		//保存
		function save() {
			var nodes = zTree.getCheckedNodes();
			var tmpNode;
			var ids = "";
			var menuIdArray = [];
			for (var i = 0; i < nodes.length; i++) {
				menuIdArray.push(nodes[i].menuId);
				
			}
			var buttonId = "${buttonId}";
			var roleId = "${roleId}";
			var url = "/admin/role/button/auth/edit";
			var postData = {};
			postData.roleId = roleId;
			postData.menuIds = menuIdArray;
			postData.buttonId = buttonId;
			$("#zhongxin").hide();
			$("#div_buttons").hide();
			$("#zhongxin2").show();
			$.post(url, postData, function(result) {
				if (result.code == 200) {
					bootbox.alert("成功", function() {
						top.Dialog.close();
					})
				} else {
					bootbox.alert(result.mes);
				}
				$("#zhongxin").show();
				$("#div_buttons").show();
				$("#zhongxin2").hide();

			});
		}
	</script>
</body>
</html>